home *** CD-ROM | disk | FTP | other *** search
- /*
- cvdemovw.cpp
-
- Main window for cvdemo
-
- C++/Views 2.0 Demo
- Copyright (c) 1992, by Liant Software Corp.
- ALL RIGHTS RESERVED.
-
- Revision History:
- -----------------
- */
-
- #include "brush.h"
- #include "cvdemovw.h"
- #include "cvdialog.h"
- #include "cvintrvw.h"
- #include "font.h"
- #include "pen.h"
- #include "popupmen.h"
- #include "port.h"
- #include "cvclass.h"
- #include "cvfeatur.h"
- #include "cvsketch.h"
- #include "cvplatfm.h"
- #include "cvorder.h"
- #include "messengr.h"
- #include "toolbar.h"
- #include "picbttn.h"
- #include "textbox.h"
- #include "yesno.h"
- #include "cvabout.h"
- #include "cvhow.h"
-
- #define TOOL_HGT 28 // height of the ToolBar Window
- #define STAT_HGT 0 // height of the Status Bar Window (if present)
- #define CLNT_HGT 380 // height of the MDI client window
- #define VIEW_HGT (TOOL_HGT+CLNT_HGT+STAT_HGT) // total height of the VMdiAppView
-
- defineClass(DemoAppView, VMdiAppView)
-
- /* menu definition */
-
- char *filechoices[] = { "E&xit",
- 0 };
-
- method filemthds[] = { methodOf(DemoAppView, menuExit),
- NIL_METHOD };
-
- char *featurechoices[] = { "&Introduction",
- "&Classes",
- "&Features",
- "&Platforms",
- 0 };
-
- method featuremthds[] = { methodOf(DemoAppView, menuIntro),
- methodOf(DemoAppView, menuClass),
- methodOf(DemoAppView, menuFeature),
- methodOf(DemoAppView, menuPlatform),
- NIL_METHOD };
-
- char *examplechoices[] = { "&Dialog...",
- "&Sketch Pad",
- 0 };
-
- method examplemthds[] = { methodOf(DemoAppView, menuDialog),
- methodOf(DemoAppView, menuSketch),
- NIL_METHOD };
-
- char *aboutchoices[] = { "About this &Demo...",
- "About the Current &Window...",
- "About &Ordering C++/Views...",
- 0 };
-
- method aboutmthds[] = { methodOf(DemoAppView, menuAbout),
- methodOf(DemoAppView, menuAboutCurrWin),
- methodOf(DemoAppView, menuOrder),
- NIL_METHOD };
-
- /* bitmaps for toolbar buttons */
- char *pix_class[] = {"BTNCLSUP", "BTNCLSDN", 0, 0 };
- char *pix_dialog[] = {"BTNDLGUP", "BTNDLGDN", 0, 0 };
- char *pix_feature[] = {"BTNFTRUP", "BTNFTRDN", 0, 0 };
- char *pix_intro[] = {"BTNCPPUP", "BTNCPPDN", 0, 0 };
- char *pix_order[] = {"BTNORDUP", "BTNORDDN", 0, 0 };
- char *pix_platform[] = {"BTNPLTUP", "BTNPLTDN", 0, 0 };
- char *pix_sketch[] = {"BTNSKHUP", "BTNSKHDN", 0, 0 };
- char *pix_how[] = {"BTNHOWUP", "BTNHOWDN", 0, 0 };
-
- /* the message dispatcher object */
- Messenger *cvTextFile;
-
- DemoAppView::DemoAppView()
- : VMdiAppView(VFrame(20, 20, 500, VIEW_HGT), VFrame(0, TOOL_HGT, 1.0F, CLNT_HGT), StyleDefault),
- aboutTopic("Intro:About"),
- aboutSource("cvdemovw.cpp")
- {
- init();
- initWindow();
-
- /* open demo text file for messages */
- cvTextFile = new Messenger("cvdemo.txt");
-
- /* force messager to find last message in file */
- /* (this will make subsequent calls to the messager faster) */
- cvTextFile->getMessage("ZZZ:lastmsg");
-
- /* popup intro window */
- menuIntro(0);
- }
-
- DemoAppView::~DemoAppView()
- {
- /* destroy background brush (if present) */
- delete getBackground();
-
- delete toolBrush;
- delete toolFont;
- }
-
- boolean DemoAppView::free()
- {
- delete this;
- return(TRUE);
- }
-
- void DemoAppView::init()
- /*
- Initialize class variables
- */
- {
- visitFlag = 0;
- tools = 0;
-
- classView = 0;
- featureView = 0;
- introView = 0;
- platformView = 0;
- sketchView = 0;
-
- toolBrush = 0;
- toolFont = 0;
- }
-
- void DemoAppView::initWindow()
- /*
- Create main menu & tool bar.
- */
- {
- /* set title and background brush for main window */
- setTitle("C++/Views 2.0");
- setBackground(new VBrush(BLUE));
-
- /* get the size of the window */
- int x, y, w, h;
- getArea(&x, &y, &w, &h);
-
- /* create the tool bar */
- tools = new ToolBar(VFrame(0, 0, 1.0F, TOOL_HGT), this);
-
- /* create buttons within the tool bar */
- VPicButton *pb;
-
- pb = new VPicButton( 5, 3, pix_class, tools);
- pb->uponClick(this, methodOf(DemoAppView, menuClass));
-
- pb = new VPicButton( 35, 3, pix_feature, tools);
- pb->uponClick(this, methodOf(DemoAppView, menuFeature));
-
- pb = new VPicButton( 65, 3, pix_platform, tools);
- pb->uponClick(this, methodOf(DemoAppView, menuPlatform));
-
- pb = new VPicButton( 95, 3, pix_dialog, tools);
- pb->uponClick(this, methodOf(DemoAppView, menuDialog));
-
- pb = new VPicButton(125, 3, pix_order, tools);
- pb->uponClick(this, methodOf(DemoAppView, menuOrder));
-
- pb = new VPicButton(155, 3, pix_sketch, tools);
- pb->uponClick(this, methodOf(DemoAppView, menuSketch));
-
- pb = new VPicButton(185, 3, pix_intro, tools);
- pb->uponClick(this, methodOf(DemoAppView, menuIntro));
-
- pb = new VPicButton(215, 3, pix_how, tools);
- pb->uponClick(this, methodOf(DemoAppView, menuAboutCurrWin));
-
- toolBrush = new VBrush(LightGray);
- toolFont = new VFont("TMS RMN", 10);
-
- /* create the pull down menu (using arrays defined above) */
- fileMenu = new VPopupMenu("&File");
- addPopup(fileMenu);
- fileMenu->addItems(filechoices, filemthds, this);
-
- featureMenu = new VPopupMenu("Fea&tures");
- addPopup(featureMenu);
- featureMenu->addItems(featurechoices, featuremthds, this);
-
- exampleMenu = new VPopupMenu("&Examples");
- addPopup(exampleMenu);
- exampleMenu->addItems(examplechoices, examplemthds, this);
-
- VPopupMenu *aboutMenu;
- aboutMenu = new VPopupMenu("&About");
- addPopup(aboutMenu);
- aboutMenu->addItems(aboutchoices, aboutmthds, this);
-
- /* Put up "Window" menu. */
- addPopup((id)mdiPopup());
- }
-
- boolean DemoAppView::close()
- /*
- The user wants to quit--ask if it's ok.
- */
- {
- return(!okToQuit());
- }
-
- boolean DemoAppView::resized(int w, int h)
- /*
- This function is called whenever our window changes size.
- */
- {
- /* resize the toolbar */
- if (tools) {
- tools->resize(w, TOOL_HGT);
- }
-
- /* resize the MDI client area */
- client.resize(w, h - (TOOL_HGT + STAT_HGT));
-
- return(TRUE);
- }
-
- void DemoAppView::updateMenu()
- /*
- Update menu bar check marks
- */
- {
- featureMenu->checkAt((introView != 0), 0);
- featureMenu->checkAt((classView != 0), 1);
- featureMenu->checkAt((featureView != 0), 2);
- featureMenu->checkAt((platformView != 0), 3);
-
- exampleMenu->checkAt((sketchView != 0), 2);
- }
-
- void DemoAppView::setAboutNames(char *tpc, char *src)
- /*
- Set topic and source names for the About Curr Win box.
- */
- {
- aboutTopic.puts(tpc);
- aboutSource.puts(src);
- }
-
- /* Menu Bar Callbacks */
-
- boolean DemoAppView::menuClass(VMenuItem *m)
- /*
- Feature-Class pulldown: give class info
- */
- {
- if (!classView) {
- classView = new ClassView(VFrame(0, 0, 500, 350), this);
- classView->bringToTop();
- visitFlag |= VISIT_CLASS;
- }
- else {
- classView->free();
- classView = 0;
- }
-
- updateMenu();
- return(TRUE);
- }
-
- boolean DemoAppView::menuPlatform(VMenuItem *m)
- /*
- Feature-Platform pulldown: give platform info
- */
- {
- if (!platformView) {
- platformView = new PlatformView(VFrame(50, 50, 300, 300), this);
- platformView->bringToTop();
- visitFlag |= VISIT_PLATFORM;
- }
- else {
- platformView->free();
- platformView = 0;
- }
-
- updateMenu();
- return(TRUE);
- }
-
- boolean DemoAppView::menuIntro(VMenuItem *m)
- /*
- Feature-Intro pulldown: give Views intro
- */
- {
- if (!introView) {
- introView = new IntroView(VFrame(0.5F, 0.5F, 0.9F, 0.9F, CenterDim), this);
- introView->bringToTop();
- }
- else {
- introView->free();
- introView = 0;
- }
-
- updateMenu();
- return(TRUE);
- }
-
- boolean DemoAppView::menuFeature(VMenuItem *m)
- /*
- Feature-Feature pulldown: give list of features
- */
- {
- if (!featureView) {
- featureView = new FeatureView(VFrame(20, 50, 500, 200), this);
- featureView->bringToTop();
- visitFlag |= VISIT_FEATURE;
- }
- else {
- featureView->free();
- featureView = 0;
- }
-
- updateMenu();
- return(TRUE);
- }
-
- boolean DemoAppView::menuOrder(VMenuItem *m)
- /*
- Feature-Order pulldown: present how-to-order dialog
- */
- {
- OrderDialog order(this);
- order.modal();
- return(TRUE);
- }
-
- boolean DemoAppView::menuDialog(VMenuItem *m)
- /*
- Example-Dialog pulldown: give dialog example
- */
- {
- DialogView dlg(this);
-
- dlg.modal();
-
- visitFlag |= VISIT_DIALOG;
- return(TRUE);
- }
-
- boolean DemoAppView::menuSketch(VMenuItem *m)
- /*
- Example-Sketch pulldown: sketchpad world example
- */
- {
- if (!sketchView) {
- sketchView = new SketchView(VFrame(50, 50, 300, 250), this);
- sketchView->bringToTop();
- visitFlag |= VISIT_SKETCH;
- }
- else {
- sketchView->free();
- sketchView = 0;
- }
-
- updateMenu();
- return(TRUE);
- }
-
- boolean DemoAppView::menuAbout(VMenuItem *m)
- /*
- File-About: Display the About box
- */
- {
- BounceAbout b(this);
-
- /* make the about dialog visible */
- b.show();
-
- /* activate the about dialog (as a modal dialog) */
- b.modal();
-
- visitFlag |= VISIT_ABOUT;
- return(TRUE);
- }
-
- boolean DemoAppView::menuAboutCurrWin(VMenuItem *m)
- /*
- File-AboutCurrWin: Display the How-it-works box for the current window
- */
- {
- HowView how(this, aboutTopic.gets(), aboutSource.gets());
-
- /* make the about how visible */
- how.show();
-
- /* activate the dialog (as a modal dialog) */
- how.modal();
-
- return(TRUE);
- }
-
- boolean DemoAppView::menuExit(VMenuItem *m)
- /*
- File-Exit: Close the application
- */
- {
- if (okToQuit()) {
- return(VAppView::close());
- }
-
- return(TRUE);
- }
-
- boolean DemoAppView::okToQuit(void)
- /*
- Ask the user if she really wants to quit.
- Returns TRUE if the user says OK.
- Use visitFlag to choose from a selection of cute messages.
- */
- {
- char *msg = "Do you wish to leave the C++/Views demo?";
-
- if (!(visitFlag & VISIT_CLASS)) {
- msg = "Leaving so soon?\nYou haven't seen the class hierarchy demo.";
- visitFlag |= VISIT_CLASS;
- }
- else if (!(visitFlag & VISIT_FEATURE)) {
- msg = "Are you sure you want to exit?\nYou haven't looked at the feature list yet.";
- visitFlag |= VISIT_FEATURE;
- }
- else if (!(visitFlag & VISIT_PLATFORM)) {
- msg = "Going already?\nBut I spent so much time on the list of supported platforms.";
- visitFlag |= VISIT_PLATFORM;
- }
- else if (!(visitFlag & VISIT_DIALOG)) {
- msg = "What's the rush?\nYou didn't try out the Example Dialog.";
- visitFlag |= VISIT_DIALOG;
- }
- else if (!(visitFlag & VISIT_SKETCH)) {
- msg = "Are you sure you want to exit?\nYou never saw the Sketch Pad example.";
- visitFlag |= VISIT_SKETCH;
- }
- else if (!(visitFlag & VISIT_ABOUT)) {
- msg = "Wait a minute!\nYou forgot to check out the About box.";
- visitFlag |= VISIT_ABOUT;
- }
-
- return(VYesNo::question(FALSE, YesButton, "Exit C++/Views Demo", this, msg) == YesButton);
- }
-
-
-